package bb.lanxing.view.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import androidx.appcompat.app.AlertDialog;
import bb.lanxing.util.DensityUtil;


public class AlertDialogBuilder extends AlertDialog.Builder {
    private int height;
    private int width;

    public AlertDialogBuilder(Context context) {
        super(context);
        this.width = -1;
        this.height = -1;
    }

    public AlertDialogBuilder(Context context, int theme) {
        super(context, theme);
        this.width = -1;
        this.height = -1;
    }

    @Override // androidx.appcompat.app.AlertDialog.Builder
    public AlertDialog show() {
        AlertDialog show = super.show();
        setButtonColor(show);
        setSize(show);
        return show;
    }

    public AlertDialogBuilder size(int width, int height) {
        this.width = width;
        this.height = height;
        return this;
    }

    public static void setButtonColor(AlertDialog alertDialog) {
        Button button = alertDialog.getButton(-2);
        if (button != null) {
            ((LinearLayout.LayoutParams) button.getLayoutParams()).setMargins(0, 0, DensityUtil.dp2px(16.0f), 0);
            button.setTextColor(Color.parseColor("#ff808080"));
        }
        Button button2 = alertDialog.getButton(-1);
        if (button2 != null) {
            button2.setTextColor(Color.parseColor("#ff007ac2"));
        }
    }

    private void setSize(AlertDialog dialog) {
        Window window;
        if ((this.width > 0 || this.height > 0) && (window = dialog.getWindow()) != null) {
            WindowManager.LayoutParams attributes = window.getAttributes();
            int i = this.height;
            if (i > 0) {
                attributes.height = i;
            }
            int i2 = this.width;
            if (i2 > 0) {
                attributes.width = i2;
            }
            window.setAttributes(attributes);
        }
    }
}
